//
//  LBUserManage.m
//  PandaTakeaway
//
//  Created by smufs on 2017/6/13.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "LBUserManage.h"
#import "BaseNavigationController.h"
//#import "LoginViewController.h"

NSString * const kHormoneIMConnectSuccessNotification = @"kHormoneIMConnectSuccessNotification";

@interface LBUserManage ()

@end

@implementation LBUserManage


+(instancetype)defaultManager {
    
    static LBUserManage *manager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [[LBUserManage alloc] init];
        
    });
    
    return manager;
}

- (void)setupManager {
    
}

- (void)setUserModel:(UserModel *)userModel{
    if (!userModel) {
        return;
    }
    _userModel = userModel;
    _isLogin_RC = YES;
    [[NSUserDefaults standardUserDefaults] setObject:[_userModel yy_modelToJSONString] forKey:USER_MODEL_KEY];
}

- (void)logout {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:USER_MODEL_KEY];
    self.userModel = nil;
    _isLogin_RC = NO;
}

- (void)verificationUserLogin:(void (^)(BOOL))block {
    
    _verificationBlock = block;
    
    if (self.userModel)
    {
        [self callBackLoginBlock:YES];
    }
    else
    {
        //        LoginViewController *loginVC = [LoginViewController new];
        //        BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:loginVC];
        //        [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:nav animated:YES completion:nil];
        
    }
}

- (void) callBackLoginBlock:(BOOL) isSuccess {
    
    if (self.verificationBlock)
    {
        
        self.verificationBlock(isSuccess);
        _verificationBlock = nil;
    }
}

- (NSString *)user_id {
    
    return self.userModel.ID;
}

- (NSString *)mobileNumber {
    
    return self.userModel.MOBILE;
}

- (NSString *)memberId {

    return self.userModel.ID;
}

- (NSString *)sellerId {

    return self.userModel.ID;
}

@end
